/***************************************************************
Copyright © 206cd Co., Ltd. 1998-2029. All rights reserved.
文件名		: drm_plane_drv.h
作者	  	: gaoweijun
版本	   	: V1.0
描述	   	: drm plane驱动文件。
其他	   	: 无
日志	   	: 初版V1.0 2021/10/12 创建
***************************************************************/

#ifndef DRM_PLANE_DRV_H
#define DRM_PLANE_DRV_H

#include <stdint.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>
//#include <libkms.h>
#ifdef __cplusplus
extern "C" {
#endif

typedef struct drm_card{
    int fd;
    uint32_t crtc_id;
    uint32_t conn_id;
}drm_card;

typedef struct drm_buffer_object {
    int fd;
    uint8_t *vaddr;

    uint32_t pitch;
    uint32_t handle;
    uint32_t size;
    uint32_t bpp;

    uint32_t fb_id;
}drm_buffer_object;

typedef struct drm_plane {
    int fd;
    uint32_t plane_id;  /* the id of plane to use */
    uint32_t crtc_id;  /* the id of CRTC to bind to */
    int32_t x, y;
    uint32_t w, h;
    double scale;
    unsigned int fb_id;
    unsigned int current_buf_index;
    int buf_num;
    struct drm_buffer_object *bo;
    struct drm_buffer_object *old_bo;
    unsigned int fourcc;
}drm_plane;

int drm_card_init(struct drm_card *card_info,char *name);
int drm_card_print_info(struct drm_card drm_info);
int drm_alpha_init(struct drm_card drm_info);
int drm_set_prop(int fd,unsigned int object_id, const char *prop_name, int prop_val);
int init_plane(struct drm_plane *plane,struct drm_card drm_info,uint32_t plane_id, uint32_t width, uint32_t height,int32_t x,int32_t y,unsigned int fourcc);
int plane_destroy(struct drm_plane *plane);
void plane_destroy_all(struct drm_plane *plane,int count);
int set_crtc_mode(struct drm_card drm_info,int mode_index);
int set_crtc_mode_v2(struct drm_card drm_info,int mode_index,unsigned int fourcc);
int plane_fb_cpy(struct drm_plane *p,void * addr,unsigned int size);
int plane_double_fb_cpy(struct drm_plane *p,void * addr,unsigned int size);
int plane_switch_buffer(struct drm_plane *p,unsigned char buf_count);


//int set_plane(struct drm_plane *p);
//int bo_create_dumb(int fd,struct drm_buffer_object *bo, unsigned int width, unsigned int height, unsigned int bpp);
//void bo_create(int fd,struct drm_buffer_object *bo, unsigned int format,
//      unsigned int width, unsigned int height,
//      unsigned int handles[4], unsigned int pitches[4],
//      unsigned int offsets[4]);
//void bo_destroy(struct drm_buffer_object *bo);
//int plane_bind_buf(int fd, struct drm_plane *p,struct drm_buffer_object plane_bo);
//int init_drm_bufs(int fd,struct drm_buffers *drm_bufs,int32_t width,int32_t height,int buf_num,unsigned int fourcc);
//void drm_bufs_destroy(struct drm_buffer_object *bufs,int buf_num);


#ifdef __cplusplus
}
#endif


#endif // V4L2_START_H
